﻿/*
var siteurl = "http://www.pickegg.com";
var imageurl = "http://resources.pickegg.com";
var payurl = "http://www.pickegg.com/pay";

var siteurl = "http://localhost:83";
var imageurl = "http://localhost:82";
var payurl = "http://localhost:888/pay";
*/
// ===================================================================================== 公共方法
var siteurl = "http://www.pickegg.com";
var imageurl = "http://resources.pickegg.com";
var payurl = "http://www.pickegg.com/pay";
var ShoppingCartType = true;
var isClickCurrecy = false;

// 购物车转向地址
function GoCart() {
    if (ShoppingCartType) {
        location.href = 'http://www.pickegg.com/pay/';
    } else {
        location.href = 'http://www.pickegg.com/Shopping/ShopCart.html';
    }
}
function GoCart1(obj) {
    if (ShoppingCartType) {
        obj.href = 'http://www.pickegg.com/pay/';
    } else {
        obj.href = 'http://www.pickegg.com/Shopping/ShopCart.html';
    }
}

var cookieEnabled = (navigator.cookieEnabled) ? true : false;
if (!cookieEnabled)
    alert('Your browser does not support Cookie, will not be finished shopping!');

// 初始化
$(document).ready(function () {
    $("#ckpcode").click(function () {
        if ($("#ckpcode").attr("checked")) {
            $("#pCoupon").show();
        } else {
            $("#pCoupon").hide();
        }
    });
    //代发货选项,设置到Cookie
    $('#cbDropShipping').click(function () {
        $.ajax({
            type: "POST",
            url: "ASHX/newCart.ashx",
            data: "type=isdropshipping&check=" + ($('#cbDropShipping').attr('checked') ? '1' : '0'),
            cache: false,
            success: function (data) {
                if (data == '0') {
                    alert('mistake happen !');
                }
            }
        });
    });

    $("#Cb_Paypal").click(function () {
        var strCart = $("#HiddenCart").val();
        if (strCart != "") {
            if ($(this).attr("checked")) {
                $("#submitPaypal").click(function () {
                    return true;
                });
            }
            else {
                $("#submitPaypal").click(function () {
                    return false;
                });
            }
        }
    });

    $("label img").live("click", function () {
        $("#" + $(this).parents("label").attr("for")).click();
    });

    $("#mbcc input[type=radio]").live("click", function () {

        if ($('#abankpaypal1 img').attr('src') != 'images/next_step1.jpg') {
            orderconfirmMuil(2, this.value);
            $("#dvPay").hide();
            $("#ifrpay").show();
            $("#cctype").html("<img src='" + $('label[for=' + this.id + '] > img').attr('src') + "' />");
        } else {
            return false;
        }
    });

    // 我的帐号与货币切换
    var timeoutObj = null;
    $("#ship_total").each(function () {
        var self = $(this);
        self.hover(function () {
            clearTimeout(timeoutObj);
            timeoutObj = setTimeout(function () {
                self.find("div:first").slideDown("500");
                $("#morecurrent").attr("src", "images/ship_ico2_1.jpg");
            }, 1000);
        }, function () {
            clearTimeout(timeoutObj);
            timeoutObj = setTimeout(function () {
                self.find("div:first").slideUp("500");
                $("#morecurrent").attr("src", "images/ship_ico2.jpg");
            }, 1000);
        });
    });

    // 币种切换
    $("#div_Currencies_list > p").each(function () {
        var self = $(this);
        self.bind("click", function () {
            isClickCurrecy = true;
            //alert(isClickCurrecy);
            $.ajax({
                type: "POST",
                url: "ASHX/SetCurrency.ashx?CurrecyType=" + self.attr("id"),
                async: false,
                cache: false,
                success: function (data) {
                    window.location.reload();
                }
            });

        });
    });

    // 判断登陆
    if (UserLoginState() != " ") { // 已登陆        
        $("#btu").show();
        $("#dvlogin1,#dvlogin2,#ContentDiv_login,#pctermsUse,#phTerms").hide();
    } else { // 未登陆  
        $("#ContentDiv_login,#pctermsUse").show();
        $("#btu").hide();
    }

    //  验证 
    using(["validatebox", "messager"], function () {
        $("#txtFirstName,#txtLastName,#txtAddress1,#txtZip,#txtCity,#txtPhone").validatebox({ required: "true", missingMessage: "Can not be empty!" });
        $("#txtFirstName1,#txtLastName1,#txtAddress11,#txtZip1,#txtCity1,#txtPhone1").validatebox({ required: "true", missingMessage: "Can not be empty!" });

        if (UserLoginState() != " ") {
        } else {
            $("#txtEmail").validatebox({ required: "true", missingMessage: "Can not be empty!" });
            $("#txtPass1,#txtPass2").validatebox({ required: "true", missingMessage: "Can not be empty!" });
            $("#txtEmail1,#txtPass11,#txtPass21").validatebox({ required: "true", missingMessage: "Can not be empty!" });
        }
    });

    //    if (getCookie("AllPageTip") == null) {
    //        var shtml = "";
    //        shtml += "<div id=\"divNotice2011\" class=\"notice2011\" >";
    //        shtml += "<b>NOTICE:</b> We are on our Spring Festival Holiday. Despatch of your order would be delayed to 10th Feb. We would like to offer a sweet gift for each order placed during the holiday. <a href=\"http://www.pickegg.com/Customer/HappyNewYear.html\" target=\"_blank\" rel=\"nofollow\" class=\"color2\">see more</a>";
    //        shtml += "<a href=\"javascript:void(0);\" class=\"notice2011_colse\"></a>";
    //        shtml += "</div>";

    //        $(shtml).prependTo("body").find(".notice2011_colse").bind("click", function () {
    //            SetCookie("AllPageTip", "true");
    //            $(this).parent().remove();
    //        });
    //    }
});

function EditOption(st) {
    $("#spanProductOption" + st).hide();
    $("#spanProductOption_" + st).show();
    $("#spanProductOption_" + st + " span[name=spoption]").html($("#spanProductOption_" + st + " input[name=TitleName]").val() + ":");
    var hfNum = $("#spanProductOption_" + st).find("span[name=spoption]").size();
    for (var i = 0; i < hfNum; i++) {
        $("#spanProductOption_" + st + " span[name=spoption]").eq(i).html($("#spanProductOption_" + st + " input[name=TitleName]").eq(i).val().replace("ProductColor", "Color") + ":");
    }
}

function EditOptionhide(st) {
    $("#spanProductOption" + st).show();
    $("#spanProductOption_" + st).hide();

}

// 切割并返回第一个值
function getsplitVa(va,split) {
    if (va.indexOf(split) > -1) {
        return va.substring(0, va.indexOf(split));
    } else
        return va;
}

// 更新购买参数选择框
function updateOption(st) {
    Operating("");
    var object = $("#spanProductOption_" + st);
    var object1 = $("#spanProductOption" + st);
    var hfNum = object.find("#TitleName").size();
    var TitleNamelist = "";
    var selectID = "";
    for (var i = 0; i < hfNum; i++) {
        if (i == 0) {
            selectID = object.find("#select" + i).val();
            TitleNamelist = object.find("#TitleName").eq(i).val() + ":" + getsplitVa(object.find("#select" + i + " option:selected").text(),'(');
        }
        else {
            selectID += "|" + object.find("#select" + i).val();
            TitleNamelist += "|" + object.find("#TitleName").eq(i).val() + ":" + getsplitVa(object.find("#select" + i + " option:selected").text(),'(');
        }
        object1.find('p').eq(i).html(object.find("#TitleName").eq(i).val() + ":" + getsplitVa(object.find("#select" + i + " option:selected").text(),'('));
    }
    //alert("ASHX/UpdateCart.ashx?Pid=" + st + "&name=" + TitleNamelist + "&OptionId=" + selectID);
    if (selectID != "") {
        $.ajax({
            type: "POST",
            url: "ASHX/UpdateCart.ashx?Pid=" + st + "&name=" + TitleNamelist + "&OptionId=" + selectID,
            success: function () {
                object1.show();
                object.hide();
                DeleteDialog();
                getProductCart();
            }
        });
    }
}

// 首页LOGO
$("#aPageLogo").hover(function () {
    $("#homepage").css("visibility", "visible");
}, function () {
    $("#homepage").css("visibility", "hidden");
});

function showhelp(id) {
    window.open(siteurl + '/Help/helpDetailSmall-' + id + '.html', 'newwindow', 'height=720, width=640, top=0, left=0, toolbar=no, menubar=no, scrollbars=yes, resizable=yes,location=no, status=no');
}

// ===================================================================================== 登陆注册

// 登陆信息
function UserLoginState() {
    var flag = "";
    $.ajax({
        type: "POST",
        url: "ASHX/loginInfo.ashx",
        async: false,
        data: { Actions: "GETUSERLOGINSTATE" },
        success: function (r) {
            flag = r;
        }
    });
    return flag;
}

// 退出登陆
function userloginOut() {
    $.ajax({
        type: "POST",
        url: "ASHX/loginInfo.ashx?isOut=1",
        data: { Actions: "ISOUT" },
        success: function (msg) {
            var href = window.location.href.toLowerCase();
            if (href.indexOf('paypalsuccessful.aspx') > -1)
                location.href = siteurl + '/';
            else
                window.location.reload();
        }
    });
}
//  登陆弹出窗口
function userSendLogin(st) {
    var cookieName = "RememberMe";
    var cookieValue = "";
    var arr = document.cookie.match(new RegExp("(^| )" + cookieName + "=([^;]*)(;|$)"));
    if (arr != null) { cookieValue = unescape(arr[2]); }

    var shtml = "";

    shtml += "<div id='loginShowDiv_title' ><ul class='loginShowc2_list'><li id='loginShowDivLi_1' class='loginShowc2_list_now'>Login<span></span></li><li  id='loginShowDivLi_2' class='loginShowc2_list_list'>Register<span></span></li></ul></div>";
    // 登陆 
    shtml += "<div class='loginShow' id='loginShow_1'>";
    shtml += "    <div class='loginShowDiv'>";
    shtml += "        <span>Dear customer</span>,Welcome back!</div>";
    shtml += "    <dl>";
    shtml += "        <dt>Email address:</dt>";
    shtml += "        <dd>";
    shtml += "            <input id='LoginEmailShow' value='" + cookieValue + "'/></dd>";
    shtml += "    </dl>"
    shtml += "    <dl>"
    shtml += "       <dt>Password:</dt>";
    shtml += "        <dd>";
    shtml += "            <input type='password'  id='LoginPassWordShow' /></dd>";
    shtml += "    </dl>";

    shtml += "    <dl>"
    shtml += "       <dt>&nbsp;</dt>";
    shtml += "        <dd>";
    shtml += "            <input type='checkbox' id='chkRememberMe' style='vertical-align:middle;' checked='CHECKED' /> <label for='chkRemember'>Remember me and automatically login.</label></dd>";
    shtml += "    </dl>";
    shtml += "    <ul>";
    shtml += "        <li  style='width:350px; line-height:24px; height:24px; padding-left:4px; margin-left:50px; border:1px solid #e3d1d1; background:#fce8e9 url(../Images/wrong.jpg) no-repeat 4px center;display:none;' id='loginSpanShow'></li>";
    shtml += "    </ul>";

    shtml += "    <dl>";
    shtml += "        <dt>";
    shtml += "            <input type='button' id='LoginSubmitShow' class='sign_in_button' value='&nbsp;' /></dt> ";
    shtml += "           <dd  style=' padding-top:4px;'> <a  style='color:#157ACC;text-decoration:underline' href='/Customer/ForgotPassword.html'>Forgot your password?</a> </dd>";
    shtml += "    </dl>";

    shtml += "</div>";


    // 注册 
    shtml += "<div class='loginShow' id='loginShow_2' style='display:none'>";
    shtml += "    <div class='loginShowDiv'>";
    shtml += "        If you don't have a PickEgg.com account, please create one .</div>";
    shtml += "    <dl>";
    shtml += "        <dt>Email address:</dt>";
    shtml += "        <dd>";
    shtml += "            <input id='LoginEmailShow_1' /></dd>";
    shtml += "    </dl>"
    shtml += "    <dl>"
    shtml += "       <dt>Password:</dt>";
    shtml += "        <dd>";
    shtml += "            <input type='password'  id='LoginPassWordShow_1' /></dd>";
    shtml += "    </dl>";
    shtml += "    <dl>"
    shtml += "       <dt>Confirm password:</dt>";
    shtml += "        <dd>";
    shtml += "            <input type='password'  id='LoginConfirmShow' /></dd>";
    shtml += "    </dl>";


    shtml += "    <dl>"
    shtml += "       <dt><input type='checkbox' id='chkAgreee' checked='checked' style='vertical-align:middle;'/></dt>";
    shtml += "        <dd style='width:200px;padding-top:4px;'>";
    shtml += "         I agree to accept the <a href='javascript:;' onclick='showhelp(54);' style='color:#414141;text-decoration: underline;'>Terms of Use</a></dd>";
    shtml += "    </dl>";

    shtml += "    <dl>"
    shtml += "        <dd>";
    shtml += "            <div style='width:270px; line-height:24px; height:24px; padding-left:25px; margin-left:50px; border:1px solid #e3d1d1; background:#fce8e9 url(../Images/wrong.jpg) no-repeat 4px center;display:none;' id='divRegistCheckUser'>Email you entered already exists, please re-enter.</div></dd>";
    shtml += "    </dl>";

    shtml += "    <ul>";
    shtml += "        <li>";
    shtml += "            <input type='button' id='ReginsterSubmitShow' value='' class='account_button' />";
    shtml += "        </li>";
    shtml += "    </ul>";
    shtml += "    <ul>";
    shtml += "        <li  style='color:red' id='loginSpanShow'></li>";
    shtml += "    </ul>";
    shtml += "</div>";

    $.modal(shtml, { opacity: 40, minHeight: 230, minWidth: 400, maxHeight: 600, maxWidth: 800, focus: true, overlayClose: true, autoResize: true });

    // start
    $("#loginShowDiv_title").find("li").each(function () {
        // 绑定事件
        $(this).bind({
            click: function () {

                $("#loginShowDiv_title").find(".loginShowc2_list_now").attr("class", "loginShowc2_list_list");
                $(this).attr("class", "loginShowc2_list_now");

                $(".loginShow").hide();
                $("#loginShow_" + $(this).attr("id").split("_")[1]).show();
            }
        });
    });

    if (st == "re") {
        $("#loginShowDiv_title").find(".loginShowc2_list_now").attr("class", "loginShowc2_list_list");
        $("#loginShowDivLi_2").attr("class", "loginShowc2_list_now");
        $(".loginShow").hide();
        $("#loginShow_2").show();
        $.modal.impl.setContainerDimensions();
    }
    else {
        $("#loginShowDiv_title").find(".loginShowc2_list_now").attr("class", "loginShowc2_list_list");
        $("#loginShowDivLi_1").attr("class", "loginShowc2_list_now");

        $(".loginShow").hide();
        $("#loginShow_1").show();
        $.modal.impl.setContainerDimensions();
    }

    // end

    using(["validatebox", "messager"], function () {
        // -1

        $.extend($.fn.validatebox.defaults.rules, {
            PasswordConfrim: {
                validator: function (value) {
                    var inputError = true;
                    var pwd1 = $("#LoginPassWordShow_1").val();
                    var pwd2 = $("#LoginConfirmShow").val();
                    if (pwd1 != pwd2) {
                        inputError = false;
                    }
                    return inputError;
                },
                message: 'Please enter at least {0} characters.'
            }, checkboxConfirm: {
                validator: function (value) {
                    var inputError = true;
                    var pwd1 = $("#chkAgreee").attr("checked");
                    if (!pwd1) {
                        inputError = false;
                    }
                    return inputError;
                },
                message: 'Please enter at least {0} characters.'
            },
            Only: {
                validator: function (value, param) {
                    var r = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/i.test(value);
                    if (r) {
                        this.message = "Email you entered already exists, please re-enter.";
                        return r;
                    } else {
                        this.message = "Please enter a valid email address.";
                        return r;
                    }
                },
                message: 'Email you entered already exists, please re-enter'
            }
        });

        // -1
        // 登陆 start
        $("#LoginEmailShow,#LoginEmailShow_1").validatebox({ required: "true", missingMessage: "Can not be empty!", validType: "email", invalidMessage: "Please enter a valid email address." });
        $("#LoginPassWordShow,").validatebox({ required: "true", missingMessage: "Can not be empty!" });
        // end    

        $("#LoginEmailShow_1").validatebox({ required: "true", validType: "Only['ASHX/Com.ashx']" });
        $("#LoginPassWordShow_1").validatebox({ required: "true", missingMessage: "Can not be empty!", validType: "length[1,20]", invalidMessage: "The character should be between 1 and 20 in length.(A-Z, a-z, 0-9)." });
        $('#LoginConfirmShow').validatebox({ required: "true", missingMessage: "Can not be empty!", validType: "PasswordConfrim", invalidMessage: "please confrim password." });
        $('#chkAgreee').validatebox({ validType: "checkboxConfirm", invalidMessage: "Please tick here." });


        $("#LoginSubmitShow").bind("click", function () {

            if ($('#LoginEmailShow').validatebox("isValid") && $('#LoginPassWordShow').validatebox("isValid")) {

                var strRememberMe = 1;
                if ($("#chkRememberMe").checked == false)
                    strRememberMe = 1;

                if (strRememberMe == 1) {
                    var Days = 1;
                    var exp = new Date();
                    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
                    document.cookie = "RememberMe" + "=" + escape($("#LoginEmailShow").val()) + ";expires=" + exp.toGMTString();
                }
                else {
                    var Days = 1;
                    var exp = new Date();
                    exp.setTime(exp.getTime() - Days * 24 * 60 * 60 * 1000);
                    document.cookie = "RememberMe" + "=" + escape($("#LoginEmailShow").val()) + ";expires=" + exp.toGMTString();
                }

                $.ajax({
                    type: "POST",
                    url: "ASHX/LoginSend.ashx",
                    data: "loginName=" + $("#LoginEmailShow").val() + "&loginPwd=" + $("#LoginPassWordShow").val() + "&RememberMe=" + strRememberMe,
                    success: function (msg) {
                        if (msg == "ok") {
                            window.location.reload();
                        }
                        else {
                            $("#loginSpanShow").show();
                            $("#loginSpanShow").html("Email address or password incorrect, please try again.");
                            $("#LoginPassWordShow").attr("value", "");

                        };
                    }
                });
            }
        });

        $("#ReginsterSubmitShow").bind("click", function () {

            if ($('#LoginEmailShow_1').validatebox("isValid") && $('#LoginPassWordShow_1').validatebox("isValid") && $('#LoginConfirmShow').validatebox("isValid") && $('#chkAgreee').validatebox("isValid")) {
                $('#divRegistCheckUser').show();
                $('#divRegistCheckUser').html("please wait...");

                $.ajax({
                    type: "POST",
                    url: "ASHX/Com.ashx",
                    async: false,
                    data: { Actions: 'ISONLY', Key: $('#LoginEmailShow_1').val() },
                    success: function (data) {
                        r = data;
                        if (!r) {
                            $('#divRegistCheckUser').show();
                            $('#divRegistCheckUser').html("Email you entered already exists.");
                            return false;
                        }
                        else {
                            $.ajax({
                                type: "POST",
                                url: "ASHX/LoginSend.ashx",
                                data: "loginName=" + $("#LoginEmailShow_1").val() + "&loginPwd=" + $("#LoginPassWordShow_1").val() + "&type=1",
                                success: function (msg) {
                                    if (msg == "ok") {
                                        window.location.reload();
                                    }
                                }
                            });
                        }
                    }
                });
            }
        });
    });


};

// =========================================================================================== 购物车处理

// 货币
var current = $("#hidCurrent").val();

// 运费选择
function Shipping_Select() {
    var txtSP = "";
    var sh = $("#Shipping_div");
    var lbs = $("#ListBoxShipping").val();
    if (lbs == "2") {
        if (sh.is(":hidden")) {
            var strHiddenShipping = $("#HiddenShipping").val();
            if (strHiddenShipping == "ok") {
                txtSP = "Free shipping, package can be tracked, 8-15 business days of transportation time.";
            }
            else {
                txtSP = "10-15 business days of transportation; package cannot be tracked. We highly recommend you select the service of ‘Get a Tracking Numbers’ to make your package trackable.";
            }
        }
        else {
            if ($("#ckshipping").attr("checked")) {
                txtSP = "Free shipping, package can be tracked, 8-15 business days of transportation time.";
            }
            else {
                txtSP = "10-15 business days of transportation; package cannot be tracked. We highly recommend you select the service of ‘Get a Tracking Numbers’ to make your package trackable.";
            }
        }
    }
    else {
        txtSP = "Package can be tracked; 3-7 business days of transportation; transportation mode will be UPS, EMS or DHL.";
    }

    $("#AirMail_P").html(txtSP);


}

// 获取购物车信息
function getProductCart() {
    // 设置初始化信息
    $("#spprice3").html(current + " 0.00");
    $("#spprice2").html(current + " 0.00");
    $("#spprice1").html(current + " 0.00");
    $("#LiteralShippingSubtotal").html(current + " 0.00");
    $("#LiteralProductSubtotal").html(current + " 0.00");
    $("#LiteralGrandTotal").html("<span class='font_16 underline'  >" + current + "</span> <span class='font_16'>0.00</span>");

    // 判断登陆
    if (UserLoginState() != " ") {
        // 已登陆
        $("#ContentDiv_login").hide();
        $("#phTerms").hide();
    } else {
        $("#ContentDiv_login").show();
    }
    // 访问数据库
    $.ajax({
        type: "POST",
        url: "ASHX/newCart.ashx",
        data: "type=productcart&shipping=" + $('#ckshipping').attr('checked'),
        async: false,
        success: function (msg) {
            if ($.trim(msg) != "") {
                $("#cartlist").html(msg);
                if (msg.indexOf('Back to Homepage') > -1) {
                    // 空购物车                   
                    $("#submitPaypal").attr("oclick", "return false");
                    $("#onclickimage").attr("oclick", "return false");
                    $("#onclickimage_2").attr("oclick", "return false");
                    $("#Shipping_div").hide();
                } else {
                    $("HiddenCart").val("ok");
                }
            }
        }
    });

    // 获取国家信息
    $.ajax({
        type: "POST",
        url: "ASHX/newCart.ashx",
        data: "type=country",
        async: false,
        success: function (msg) {
            if ($.trim(msg) != "") {
                // 返回格式 226{@}US{@}United States{@}US    取第一个值226
                $("#HiddenselCountry").val(msg.split("{@}")[0]);
                $("#selCountry").val(msg.split("{@}")[0]);
                $("#LiteralCountry").html("<img src='" + imageurl + "/Images/Country/flag/" + msg.split("{@}")[1] + ".gif' /> ");
            }
            DeleteDialog();
        }
    });

    // 重新计算运费显示提示
    Shipping_Select();

    // 优惠券处理
    couponOrder();
}

// 改变国家列表
var ShopCartCount = 0;
function sendSelectLoad() {
    var stSelect = $("#selCountry").val();
    var hstSelect = $("#HiddenselCountry").val();
    if (stSelect == "226") {
        closeCheckout();
    } else {
        // google checkout限制
        //            $('#gcimg1').attr('src', 'images/pickegg_pay_botton1.jpg');
        //            $('#gcimg').click(function ()
        //            { return false; });
    }

    Operating("");
    // 设置国家信息（写入缓存中)
    if (stSelect != hstSelect) {
        $.ajax({
            type: "POST",
            url: "ASHX/getStrCountry.ashx?st=" + stSelect,
            async: false,
            success: function () {
                getProductCart();
                DeleteDialog();
            }
        });
        HeaderDountry();
    }
}
// 获取国家列表值
function HeaderDountry() {
    $.ajax({
        type: "POST",
        url: "ASHX/getStrCountry.ashx",
        data: "",
        success: function (msg) {
            if (msg != "") {
                $("#Country_li").html("Free shipping to <img src='" + imageurl + "/Images/Country/flag/" + msg.split("{@}")[1] + ".gif' style='vertical-align: middle;' /> " + msg.split("{@}")[1]);
                $("#hidCounter").val(msg.split("{@}")[3]);
            }
        }
    });
}

// 选择运费
function sendSelectShippingLoad() {
    Operating("");
    var s = $("#ListBoxShipping").val();
    SetCookie("SELECT_SHIPPING_TYPE", s);
    if (s == "1") { // 非免费处理
        if (getCookie("shippingType") != "" && getCookie("shippingType") != null) {
            $("#ckshipping").attr("checked", false);
        }
    }
    // 写入cookie shipping
//    $.ajax({
//        type: "POST",
//        url: "ASHX/newCart.ashx",
//        data: "type=cookie&c=" + $("#ListBoxShipping").val(),
//        success: function (msg) { DeleteDialog(); }
//    });
    getProductCart();
    DeleteDialog();
}
// 选择运费
function sendSelectShippingLoadmini() {
    var s = $("#ListBoxShipping").val();
    if (s == "1") { // 非免费处理
        if (getCookie("shippingType") != "" && getCookie("shippingType") != null) {
            $("#ckshipping").attr("checked", false);
        }
    }
    // 写入cookie
    $.ajax({
        type: "POST",
        url: "ASHX/newCart.ashx",
        data: "type=cookie&c=" + $("#ListBoxShipping").val()
    });
}
// 更新购物车产品数量(输入框)
function updateCartNum(strid, str_id, stNum) {

    var p_num = $("#" + strid).val();
    if (p_num != stNum) {
        Operating("");
        if (p_num != "0" && p_num != "") {
            // ProductCart.ProductCartUpdateNum(p_num,strid,str_id);
            $.ajax({
                type: "POST",
                url: "ASHX/ProductCart.ashx",
                data: "P_num=" + p_num + "&strID=" + strid + "&str_ID=" + str_id,
                success: function (msg) {
                    getProductCart();
                    DeleteDialog();
                }
            });
        }
        else {
            // 需添加AJAX加载价格，国家列表，快递方式列表
            getProductCart();
            DeleteDialog();
        }
    } else {
        DeleteDialog();
    }

}
// 减操作
function ProductNum(strid, str_id, stNum) {
    Operating("");
    if (stNum != "0" && stNum != "") {
        $.ajax({
            type: "POST",
            url: "ASHX/newCart.ashx",
            data: "type=productnum&P_num=" + stNum + "&strID=" + strid + "&str_ID=" + str_id,
            success: function (msg) {
                getProductCart();
                $("#" + strid).val(msg);
                DeleteDialog();
            }
        });
    }
}
// 添数量
function ProductNumAdd(strid, str_id, stNum) {
    Operating("");
    if (stNum != "0" && stNum != "") {
        $.ajax({
            type: "POST",
            url: "ASHX/newCart.ashx",
            data: "type=productnumAdd&P_num=" + stNum + "&strID=" + strid + "&str_ID=" + str_id,
            success: function (msg) {
                getProductCart();
                //$("#" + strid).val(msg);
                DeleteDialog();
            }
        });
    }
}
// 输入优惠券
function couponOrder() {
    if ($('#txtCoupon').val() == "" && (getCookie("CouponCode") == null || getCookie("CouponCode") == "" || getCookie("CouponCode") == "962D99C62776500E")) {
        $("#ckpcode").attr("checked", false);
        $('#pOrderCoupon').hide();
        return;
    }

    Operating("");

    if ($('#txtCoupon').val() == "" && getCookie("CouponCode") != null && getCookie("CouponCode") != "962D99C62776500E" && getCookie("CouponCode") != "")
    {
        $('#txtCoupon').val("******");
    }

    var code = $('#txtCoupon').val();

    $.ajax({
        type: "POST",
        url: "ASHX/newCart.ashx",
        data: "type=coupon&price=" + $("#LiteralProductSubtotal").html() + "&price1=" + $("#LiteralShippingSubtotal").html() + "&code=" + (($('#txtCoupon').val() != "" && $('#txtCoupon').val() != undefined) ? $('#txtCoupon').val() : "******"),
        async: false, //取消异步请求
        success: function (msg) {
            // 处理优惠券信息
            switch (msg.substring(0, 1)) {
                case "":
                    if ($("#pCoupon").html().indexOf('Cupon Area') == -1) {
                        $("#pCoupon").html("<div><input type=\"text\" class=\"text_t\" value=\"\" id=\"txtCoupon\" onclick=\"this.value=''\" /><input type=\"button\" value=\"\" onclick=\"javascript:couponOrder()\" class=\"text_i\"   /></div><p style=\"display:none\"></p>");
                    }
                    $("#pCoupon > p").show();
                    $("#pCoupon > p").html("Sorry, the coupon dose not exist!");
                    $("#txtCoupon").val(code);
                    $("#pCoupon").show();
                    $("#ckpcode").attr("checked", true);
                    $('#pOrderCoupon').hide();
                    break;
                case "1":
                    if ($("#pCoupon").html().indexOf('Cupon Area') == -1) {
                        $("#pCoupon").html("<div>Cupon Area:<input type=\"text\" class=\"text_t\" value=\"\" id=\"txtCoupon\" onclick=\"this.value=''\" /><input type=\"button\" value=\"\" onclick=\"javascript:couponOrder()\" class=\"text_i\" /></div><p style=\"display:none\"></p>");
                    }
                    $("#pCoupon > p").show();
                    $("#pCoupon > p").html("Sorry, the coupon is expired!");
                    $("#txtCoupon").val(code);
                    $("#pCoupon").show();
                    $("#ckpcode").attr("checked", true);
                    $('#pOrderCoupon').hide();
                    break;
                case "2":
                    if ($("#pCoupon").html().indexOf('Cupon Area') == -1) {
                        $("#pCoupon").html("<div>Cupon Area:<input type=\"text\" class=\"text_t\"  value=\"\" id=\"txtCoupon\" onclick=\"this.value=''\" /><input type=\"button\" value=\"\" onclick=\"javascript:couponOrder()\" class=\"text_i\" /></div><p style=\"display:none\"></p>");
                    }
                    $("#pCoupon > p").show();
                    $("#pCoupon > p").html("Sorry, the coupon is invalid!");
                    $("#txtCoupon").val(code);
                    $("#pCoupon").show();
                    $("#ckpcode").attr("checked", true);
                    $('#pOrderCoupon').hide();
                    break;
                case "3":
                    if ($("#pCoupon").html().indexOf('Cupon Area') == -1) {
                        $("#pCoupon").html("<div>Cupon Area:<input type=\"text\" class=\"text_t\" value=\"\" id=\"txtCoupon\" onclick=\"this.value=''\" /><input type=\"button\" value=\"\" onclick=\"javascript:couponOrder()\" class=\"text_i\" /></div><p style=\"display:none\"></p>");
                    }
                    $("#pCoupon > p").show();
                    //   $("#pCoupon > p").html("Sorry, the coupon is valid for the order over $" + msg.substring(2) + "!");
                    $("#txtCoupon").val(code);
                    if (($('#txtCoupon').val() == "")) {
                        $('#txtCoupon').val("******");
                    }
                    $("#spcoupon").html(msg.substring(2));
                    $("#pCoupon").show();
                    $("#ckpcode").attr("checked", true);
                    $('#pOrderCoupon').hide();
                    break;
                default:
                    {
                        // 有效优惠券
                        $("#pCoupon").html("<span style='float:right'><a href='javascript:;' title='The binding coupon is canceled!' onclick='javascript:clearCoupon()'>X</a>&nbsp;</span><p style=\"text-align:center; width:280px; color:#666; line-height:16px;\">You have entered the coupon.</p>");
                        $("#spcoupon").html(msg);
                        $("#pCoupon").show();
                        $("#ckpcode").attr("checked", true);
                        $('#pOrderCoupon').show();
                    }
                    break;
            }
            DeleteDialog();
        }
    });
}

// 取消优惠券
function clearCoupon() {
    Operating("");
    $.ajax({
        type: "POST",
        url: "ASHX/newCart.ashx",
        data: "type=clearcoupon",
        success: function () {
            getProductCart();
            $("#pCoupon").html(" Cupon Area:<input type=\"text\" value=\"\" id=\"txtCoupon\" onclick=\"this.value=''\" /><input type=\"button\" value=\" \" onclick=\"javascript:couponOrder()\" class=\"text_i\"/><p style=\"display:none\"></p>");
            $('#pOrderCoupon').hide();
            DeleteDialog();
        }
    });
}

// 移除购物车单个产品
function submitDelete(str) {
    Operating("");
    $.ajax({
        type: "POST",
        url: "ASHX/UpdateCart.ashx?Pid=" + str + "&ty=1",
        success: function (msg) {
            // 需添加AJAX加载价格，国家列表，快递方式列表
            getProductCart();
            DeleteDialog();
        }
    });
}

// 选择挂号费
function ShippingSel() {
    Operating("");
    if ($('#ckshipping').attr('checked')) {
        SetCookie('IS_TRACKING_NUMBER','OK');
    } else {
        SetCookie('IS_TRACKING_NUMBER', 'NO');
    }
    $('#HiddenShipping').val('ok');
    getProductCart();
}

// 提交订单
function orderconfirm(type) {
    //alert(isClickCurrecy);
    Operating("");
    if (isClickCurrecy == false) {
        $.ajax({
            type: "POST",
            url: "ASHX/newCart.ashx?pt=" + type,
            data: "type=orderconfirm&ckshipping=" + $('#ckshipping').attr('checked') + "&shipping=" + $("#ListBoxShipping").val(),
            async: false, //取消异步请求
            success: function (msg) {
                location.href = msg;
            }
        });
    }
    else {
        alert('Please wait...');
    }
} // 用于返回html订单提交
function orderconfirmMuil(type, va) {
    if (type == 4) {
        Operating("");
    }
    $.ajax({
        type: "POST",
        url: "ASHX/newCart.ashx?pt=" + type,
        data: "type=orderconfirm&ckshipping=" + $('#ckshipping').attr('checked') + "&shipping=" + $("#ListBoxShipping").val() + "&cc=" + va,
        success: function (msg) {
            $('#spscript').html(msg);
        }
    });
}

// 登陆正常则显示登陆信息
function isLogin() {
    if (UserLoginState() != " ") {
        $("#dvlogin1,#dvlogin2,#ContentDiv_login,#pctermsUse,#phTerms").hide();
    }
}

// 提交汇款信息
function checkFrom1() {
    var strFirstName = $("#txtFirstName").val();
    var strLastName = $("#txtLastName").val();
    var strAddress1 = $("#txtAddress1").val();
    var strAddress2 = $("#txtAddress2").val();
    var strZip = $("#txtZip").val();
    var strCity = $("#txtCity").val();
    var strEmail = $("#txtEmail").val();
    var strPass1 = $("#txtPass1").val();
    var strPass2 = $("#txtPass2").val();
    var strCountry1 = $("#selCountry1").find("option:selected").text();
    var isLogin = $("#hdLoginModel1").val();
    var strPhone = $('#txtPhone').val();

    // 写入西联表单
    $("#txtFirstName1").val(strFirstName);
    $("#txtLastName1").val(strLastName);
    $("#txtAddress11").val(strAddress1);
    $("#txtAddress21").val(strAddress2);
    $("#txtZip1").val(strZip);
    $("#txtCity1").val(strCity);
    $('#txtPhone1').val(strPhone);


    // 判断表单
    if ($('#txtFirstName').validatebox("isValid") && $('#txtLastName').validatebox("isValid") && $('#txtAddress1').validatebox("isValid") && $('#txtZip').validatebox("isValid") && $('#txtCity').validatebox("isValid")) {
        $("#spError").html("");
    } else {
        $("#spError").html("Note:Please enter the complete information of the receiver.");
        return false;
    }

    // 判断是否注册新用户
    if (UserLoginState() != " ") {
        $("#spError").html("<img src='images/loading.gif' style='vertical-align:middle' /> please wait...");
        $.ajax({
            type: "POST",
            url: "ASHX/newCart.ashx",
            data: "type=banktransfer&Phone=" + strPhone + "&FirstName=" + strFirstName + "&LastName=" + strLastName + "&Address1=" + strAddress1 + "&Address2=" + strAddress2 + "&Zip=" + strZip + "&City=" + strCity + "&Country=" + strCountry1 + "&email=" + strEmail + "&shipping=" + $("#ListBoxShipping").val(),
            success: function (msg) {
                if (msg == "error") {
                    $("#spError").html("Note:Order error.");
                    return false;
                } else {
                    $("#spscript").html(msg);
                    $("#Pay1").hide();
                    $("#PayEx1").show();
                }
            }
        });
    } else {
        if (isLogin == "0") {
            // 注册加登陆
            var r = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/i.test(strEmail);
            if (!r) {
                $('#spError').html("Note:please enter a valid email address.");
                return false;
            } else {
                $('#spError').html("");
            }
            if ($('#txtEmail').validatebox("isValid") && $('#txtPass1').validatebox("isValid") && $('#txtPass2').validatebox("isValid") && strPass1 == strPass2) {
                $("#spError").html("<img src='images/loading.gif' style='vertical-align:middle' /> please wait...");

                $.ajax({
                    type: "POST",
                    url: "ASHX/Com.ashx",
                    async: false,
                    data: { Actions: 'ISONLY', Key: $('#txtEmail').val() },
                    success: function (data) {
                        r = data;
                        if (!r) { // 判断是否已存在
                            $('#spError').html("Note:Email you entered already exists.");
                            return false;
                        }
                        else {
                            $("#spError").html("<img src='images/loading.gif' style='vertical-align:middle' /> please wait...");
                            $.ajax({
                                type: "POST",
                                url: "ASHX/LoginSend.ashx",
                                data: "loginName=" + $("#txtEmail").val() + "&loginPwd=" + $("#txtPass1").val() + "&type=1",
                                success: function (msg) {
                                    $.ajax({
                                        type: "POST",
                                        url: "ASHX/newCart.ashx",
                                        data: "type=banktransfer&Phone=" + strPhone + "&FirstName=" + strFirstName + "&LastName=" + strLastName + "&Address1=" + strAddress1 + "&Address2=" + strAddress2 + "&Zip=" + strZip + "&City=" + strCity + "&Country=" + strCountry1 + "&email=" + strEmail + "&shipping=" + $("#ListBoxShipping").val(),
                                        success: function (msg) {
                                            if (msg == "error") {
                                                $("#spError").html("*Order error.");
                                                return false;
                                            } else {
                                                $("#spscript").html(msg);
                                                $("#Pay1").hide();
                                                $("#PayEx1").show();
                                            }
                                        }
                                    });
                                }
                            });
                        }
                    }
                });
            } else {
                $("#spError").html("Note:Confirm password error.");
                return false;
            }
        } else {
            // 登陆
            if ($('#txtEmail').validatebox("isValid") && $('#txtPass1').validatebox("isValid")) {
                $("#spError").html("<img src='images/loading.gif' style='vertical-align:middle' /> please wait...");
                $.ajax({
                    type: "POST",
                    url: "ASHX/LoginSend.ashx",
                    data: "loginName=" + $("#txtEmail").val() + "&loginPwd=" + $("#txtPass1").val(),
                    success: function (msg) {
                        if (msg == "no") {
                            $("#spError").html("Note:Email or password is error.");
                            return false;
                        } else {
                            $.ajax({
                                type: "POST",
                                url: "ASHX/newCart.ashx",
                                data: "type=banktransfer&Phone=" + strPhone + "&FirstName=" + strFirstName + "&LastName=" + strLastName + "&Address1=" + strAddress1 + "&Address2=" + strAddress2 + "&Zip=" + strZip + "&City=" + strCity + "&Country=" + strCountry1 + "&email=" + strEmail + "&shipping=" + $("#ListBoxShipping").val(),
                                success: function (msg) {
                                    if (msg == "error") {
                                        $("#spError").html("*Order error.");
                                        return false;
                                    } else {
                                        $("#spscript").html(msg);
                                        $("#Pay1").hide();
                                        $("#PayEx1").show();
                                    }
                                }
                            });
                        }
                    }
                });
            }
        }
    }
}

// 提交西联汇款
function checkFrom2() {
    var strFirstName = $("#txtFirstName1").val();
    var strLastName = $("#txtLastName1").val();
    var strAddress1 = $("#txtAddress11").val();
    var strAddress2 = $("#txtAddress21").val();
    var strZip = $("#txtZip1").val();
    var strCity = $("#txtCity1").val();
    var strEmail = $("#txtEmail1").val();
    var strPass1 = $("#txtPass11").val();
    var strPass2 = $("#txtPass21").val();
    var strCountry1 = $("#selCountry2").find("option:selected").text();
    var isLogin = $("#hdLoginModel2").val();
    var strPhone = $('#txtPhone1').val();

    // 写入汇款表单
    $("#txtFirstName").val(strFirstName);
    $("#txtLastName").val(strLastName);
    $("#txtAddress1").val(strAddress1);
    $("#txtAddress2").val(strAddress2);
    $("#txtZip").val(strZip);
    $("#txtCity").val(strCity);
    $('#txtPhone').val(strPhone);

    // 判断表单
    if (
        $('#txtFirstName1').validatebox("isValid")
        &&
        $('#txtLastName1').validatebox("isValid")
        &&
        $('#txtAddress11').validatebox("isValid")
        &&
        $('#txtZip1').validatebox("isValid")
        &&
        $('#txtCity1').validatebox("isValid")
        && 
        $('#txtPhone1').validatebox("isValid")) {
        $("#spError1").html("");
    } else {
        $("#spError1").html("");
        return false;
    }

    // 判断是否注册新用户
    if (UserLoginState() != " ") {
        $("#spError1").html("<img src='images/loading.gif' style='vertical-align:middle' /> please wait...");
        $.ajax({
            type: "POST",
            url: "ASHX/newCart.ashx",
            data: "type=westernunion&Phone=" + strPhone + "&FirstName=" + strFirstName + "&LastName=" + strLastName + "&Address1=" + strAddress1 + "&Address2=" + strAddress2 + "&Zip=" + strZip + "&City=" + strCity + "&Country=" + strCountry1 + "&email=" + strEmail + "&shipping=" + $("#ListBoxShipping").val(),
            success: function (msg) {
                if (msg == "error") {
                    $("#spError1").html("*Order error.");
                    return false;
                } else {
                    $("#spscript").html(msg);
                    $("#Pay2").hide();
                    $("#PayEx2").show();
                }
            }
        });

    } else {
        var r = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/i.test(strEmail);
        if (!r) {
            $('#spError1').html("Note:Please enter a valid email address.");
            return false;
        } else {
            $('#spError1').html("");
        }
        if (isLogin == "0") {
            // 注册加登陆
            if ($('#txtEmail1').validatebox("isValid") && $('#txtPass11').validatebox("isValid") && $('#txtPass21').validatebox("isValid") && strPass1 == strPass2) {
                $("#spError1").html("<img src='images/loading.gif' style='vertical-align:middle' /> please wait...");
                $.ajax({
                    type: "POST",
                    url: "ASHX/Com.ashx",
                    async: false,
                    data: { Actions: 'ISONLY', Key: $('#txtEmail1').val() },
                    success: function (data) {
                        r = data;
                        if (!r) { // 判断是否已存在
                            $('#spError1').html("Note:Email you entered already exists.");
                            return false;
                        }
                        else { // 注册成功后登陆
                            $("#spError1").html("<img src='images/loading.gif' style='vertical-align:middle' /> please wait...");
                            $.ajax({
                                type: "POST",
                                url: "ASHX/LoginSend.ashx",
                                data: "loginName=" + $("#txtEmail1").val() + "&loginPwd=" + $("#txtPass11").val() + "&type=1",
                                success: function (msg) {
                                    $("#dvlogin1,#dvlogin2,#ContentDiv_login,#pctermsUse,#phTerms").hide();
                                    $.ajax({
                                        type: "POST",
                                        url: "ASHX/newCart.ashx",
                                        data: "type=westernunion&Phone=" + strPhone + "&FirstName=" + strFirstName + "&LastName=" + strLastName + "&Address1=" + strAddress1 + "&Address2=" + strAddress2 + "&Zip=" + strZip + "&City=" + strCity + "&Country=" + strCountry1 + "&email=" + strEmail + "&shipping=" + $("#ListBoxShipping").val(),
                                        success: function (msg) {
                                            if (msg == "error") {
                                                $("#spError1").html("*Order error.");
                                                return false;
                                            } else {
                                                $("#spscript").html(msg);
                                                $("#Pay2").hide();
                                                $("#PayEx2").show();
                                            }
                                        }
                                    });
                                }
                            });
                        }
                    }
                });
            } else {
                $("#spError1").html("Note:Confirm password error.");
                return false;
            }
        }
        else {
            // 登陆
            if ($('#txtEmail1').validatebox("isValid")&&$('#txtPass11').validatebox("isValid")) {
                $("#spError1").html("<img src='images/loading.gif' style='vertical-align:middle' /> please wait...");
                $.ajax({
                    type: "POST",
                    url: "ASHX/LoginSend.ashx",
                    data: "loginName=" + $("#txtEmail1").val() + "&loginPwd=" + $("#txtPass11").val(),
                    success: function (msg) {
                        if (msg == "no") {
                            $("#spError").html("Note:Email or password is error.");
                            return false;
                        } else {
                            $("#dvlogin1,#dvlogin2,#ContentDiv_login,#pctermsUse,#phTerms").hide();
                            $.ajax({
                                type: "POST",
                                url: "ASHX/newCart.ashx",
                                data: "type=westernunion&Phone=" + strPhone + "&FirstName=" + strFirstName + "&LastName=" + strLastName + "&Address1=" + strAddress1 + "&Address2=" + strAddress2 + "&Zip=" + strZip + "&City=" + strCity + "&Country=" + strCountry1 + "&email=" + strEmail + "&shipping=" + $("#ListBoxShipping").val(),
                                success: function (msg) {
                                    if (msg == "error") {
                                        $("#spError1").html("Note:Order error.");
                                        return false;
                                    } else {
                                        $("#spscript").html(msg);
                                        $("#Pay2").hide();
                                        $("#PayEx2").show();
                                    }
                                }
                            });
                        }
                    }
                });
            }
        }
    }
}

// 添加到收藏夹
function AddAjaxFavorite(id) {
    using("messager", function () {
        $.ajax({
            type: "POST",
            url: "ashx/AddFavorite.ashx",
            data: { Actions: 'FromPay',ID: id },
            success: function (result) {
                if (result == "true") {
                    $.msg.alert("Add to Favorites Successful.", "info");
                    //		window.location.reload();
                } else {
                    $.msg.alert("Please <a id=\"aMsgLogin\" href=\"javascript:void(0);\" style=\"color:#056a9e; text-decoration:underline;\">Login</a> or <a id=\"aMsgRegister\" href=\"javascript:void(0);\"  style=\"color:#056a9e; text-decoration:underline;\">Register</a> first to add it to wishlist.", 'error');

                    $("#aMsgLogin").click(function () {
                        $.modal.close();
                        userSendLogin('lo');
                    });

                    $("#aMsgRegister").click(function () {
                        $.modal.close();
                        userSendLogin('re');
                    });
                }
            }
        });
    });
}

// ======================================================================================= 支持方法


// 显示隐藏提示层
function Operating(Dialog_Operating) {
    $.modal("<img src=\"Images/loading.gif\" align=\"absmiddle\"/> 5 to 20 seconds to process encrypted data...Please wait...", { opacity: 40, focus: true, autoResize: true, close: false, minWidth: 500 });
}
// 删除对话层
function DeleteDialog() {
    $.modal.close();
}

// 开启或关闭支付按钮
function payButton(open, str) {
    if (open == true) {
        $('#papalimg,#papalimg1,#gcimg').attr('src', 'images/pickegg_pay_botton.jpg');
        $('#abankpaypal img,#abankpaypal1 img').attr('src', 'images/next_step.jpg');
        $('#papalimg,#papalimg1,#gcimg').die();
    } else {
        $('#papalimg,#papalimg1,#gcimg').attr('src', 'images/pickegg_pay_botton1.jpg');
        $('#abankpaypal img,#abankpaypal1 img').attr('src', 'images/next_step1.jpg');
        $('#papalimg,#papalimg1,#abankpaypal,#abankpaypal1,#gcimg').live("mouseover", function () {
            var self = $(this);
            _over(self, str);
        }).live("mouseout", _out);
        $('#papalimg,#papalimg1,#gcimg,#paypallist,#abankpaypal,#abankpaypal1,#paypallist2,#paypallist1').attr('onclick', 'return false');
    }
}

// 关闭gc
function closeCheckout() {
    $('#gcimg').attr('src', 'images/pickegg_pay_botton.jpg');
    $('#gcimg').click(function ()
    { orderconfirm(3); });
}

// 鼠标进入
function _over(obj, str) {
    var self = obj;
    var tip = $("<div class=\"cart_tip\">" + "<span class=\"cart_tip_content\">" + "</span>" + "<span class=\"cart_tip_pointer\">" + "</span>" + "</div>").appendTo("body");

    tip.find(".cart_tip_content").html(str);
    var left = self.offset().left + self.outerWidth();
    tip.css({ display: "block", left: left, top: self.offset().top - tip.outerHeight() });
}

// 鼠标移出
function _out() {
    $(".cart_tip").remove();
}

function SetCookie(name, value)// 两个参数，一个是cookie的名子，一个是值
{
    var Days = 1;
    // 此 cookie 将被保存 1 天
    var exp = new Date();
    // new Date("December 31, 9998");
    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}

function getCookie(name)//取cookies函数
{
    var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
    if (arr != null) return unescape(arr[2]);
    return null;
}

function openWindow(url, height, width) {
    window.open(url, 'newwindow', 'height=' + height + ', width=' + width + ', top=0, left=0, toolbar=no, menubar=no, scrollbars=yes, resizable=yes,location=no, status=no');
}

// 网站提示
(function ($) {
    $.msg = {
        alert: function (content, icon, fn) {
            var _content = "";

            switch (icon) {
                case "error":
                    _content = "<div class=\"messager-icon messager-error\"></div><div class=\"error\"><span>Error:</span>" + content + "</div>";
                    break;
                case "info":
                    _content = "<div class=\"messager-icon messager-info\"></div><div class=\"info\"><span>Congratulations!</span>" + content + "</div>";
                    break;
                case "warning":
                    _content = "<div class=\"messager-icon messager-warning\"></div><div class=\"warning\"><span>Warning:</span>" + content + "</div>";
                    break;
            }

            _content = "<div class=\"messager\"><div class=\"messager-body\">" + _content + "</div></div>";

            //	$.modal(_content,{opacity: 40,minHeight: 100,minWidth: 400,maxHeight:600,maxWidth:800,focus:true,autoResize:true,onClose:fn});
            alert(content);

        }, confirm: function (title, content, fn) {

        }
    };



})(jQuery);


function backpage() {
    location.href = $("#TableCart .two a:last").attr("href");
}


// 显示登陆切换
function showLogin(num) {
    $("#splogininfo" + num).html("New customer? <a href='javascript:;' class='color3' onclick='javascript:showReg(" + num + ");'>Register</a>");
    $("#lbpass" + num).html("Password:");
    $("#ppass" + num).hide();
    $("#hdLoginModel" + num).val("1");
}
// 显示注册切换
function showReg(num) {
    $("#splogininfo" + num).html(" Existing customer? <a href='javascript:;' onclick='showLogin(" + num + ")' class='color3'>Login</a>");
    $("#lbpass" + num).html("Create PickEgg Password:");
    $("#ppass" + num).show();
    $("#hdLoginModel" + num).val("0");
}